//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/* Copyright 2002 Intel Corp.  */
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995, 1996, 1997  Microsoft Corporation

Module Name:

    drv_glob.h

Abstract:

    This file provides the C definitions for the driver globals area of
    shared memory, used to coordinate between ISRs and ISTs.

--*/
#ifndef _DRV_GLOB_H
#define _DRV_GLOB_H

#include "memdefs.h"			// Reserved memory addresses
#include "xllp_dmac.h"

// don't include all the c stuff for fwp2.s
#ifndef ASM_ONLY
#include "windef.h"
#include "bvd1bd.h"

// Prototype functions from drvlib
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif //_cplusplus
#endif //ASM_ONLY

//#pragma pack(1)
//#pragma pack(push,1)

#define PAD(label,amt)  UCHAR Pad##label[amt]


// Add pointer to off button flag - UPDATED for UNINITIALIZED Misc area
#ifdef MIPS
#define  MISC_GLOBALS_BASE          (DRIVER_GLOBALS_PHYSICAL_MEMORY_START + 0x804)
#define  OFFBUTTON                  0
#endif

// Make sure these match up with the defs in config.bib, and drv_glob.inc
#define DRIVER_GLOBALS_PHYSICAL_MEMORY_START  (DRIVER_GLOBALS_U_VIRTUAL)
#define DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE   0x1000  // 4K

// In OEMInit, we zero out the region specified by the following defs
#define DRIVER_GLOBALS_ZEROINIT_START  DRIVER_GLOBALS_PHYSICAL_MEMORY_START

//we don't want misc intialized either since we pass info from the kernel
#define DRIVER_GLOBALS_ZEROINIT_SIZE   0x600

// don't include all the c stuff for fwp2.s
#ifndef ASM_ONLY

#define BOOT_DEVICE_NONE	0
#define BOOT_DEVICE_SLOT0	1
#define BOOT_DEVICE_SLOT1	2
#define BOOT_DEVICE_SMC		3

#define DBG_ETH_GLOBALS_SIZE 256

// PCMCIA globals.
typedef struct DECL_PACKED _PCMCIA_GLOBALS
{
    // Used to let HAL know which level ints are enabled.
    UCHAR slot0Enable;
    UCHAR slot1Enable;
    UCHAR slot0CDvalidint;
    UCHAR slot1CDvalidint;
    UCHAR slot0BVDStschgint;
    UCHAR slot1BVDStschgint;
    PAD(0,250);          // Pad to 256 bytes
} PCMCIA_GLOBALS, *PPCMCIA_GLOBALS;

// For timing interrupt latency
typedef struct DECL_PACKED _PROFILE_GLOBALS {
    ULONG itIndex;			// index of timer interrupt (log[0])
    ULONG itCounter;		// counter at isr start (log[1])
    ULONG itSpc;			// saved stack pointer (log[2])
    PAD(0,244);          	// Pad to 256 bytes
} PROFILE_GLOBALS, *PPROFILE_GLOBALS;

// Miscellaneous
typedef struct DECL_PACKED _MISC_GLOBALS {
    UINT bcrShadow;			//this is the BCR Shadow register for the XSC1 ref design
    UCHAR BackLight;
    PAD(0,251);
} MISC_GLOBALS, *PMISC_GLOBALS;

// Un-initialized Miscellaneous
typedef struct DECL_PACKED _UNINIT_MISC_GLOBALS {
    UINT CPUSteppingID;      // Contains the Current CPU ID (including stepping)
    UCHAR offButton;        // Indicate to keyboard driver when OFF button pressed
    UCHAR USBCableEvent;    // Indicate USB Cable connect/disconnect
	UCHAR EbootDevice;
	DWORD CPUUtilization;
	UCHAR idletime;

    PAD(0,244);
} UNINIT_MISC_GLOBALS, *PUNINIT_MISC_GLOBALS;
//
// PMU Globals area
//
typedef struct DECL_PACKED _PMU_GLOBALS {
	ULONG DSAStart;
	PAD(0,252);			// Pad to 256 bytes
} PMU_GLOBALS, *PPMU_GLOBALS;

//
// AC97 Globals area
//
typedef struct DECL_PACKED _AC97_GLOBALS
{
	UCHAR GpioIsConfigured;
    PAD(0,255);          // Pad to 256 bytes

} AC97_GLOBALS, *PAC97_GLOBALS;

// For debugging over ethernet. Controls debug messages, ethernet shell
// and kernel debugger.  Note that this struct should not be zeroed
// out by OEMInit, as the eboot bootloader passes us state info.
typedef struct DECL_PACKED _DBG_ETH_GLOBALS
{
    DWORD EbootMagicNum;    // To detect if ether bootloader is present
#define EBOOT_MAGIC_NUM 0x45424F54 // "EBOT"

    UCHAR etherEnabled;     // If non-zero, ethernet card present
    UCHAR etherFlags;       // Set by eboot loader. Controls which components are enabled over ether (see ethdbg.h)
    PAD(0,2);

    DWORD SubnetMask;       // Subnet mask

//    EDBG_ADDR DownloadHostAddr; // IP and ether address of host who started us

    // The following addresses are assumed valid if the corresponding flag in
    // etherFlags is set.
//    EDBG_ADDR DbgHostAddr;   // IP/ether addr and UDP port of host receiving dbg msgs
//    EDBG_ADDR KdbgHostAddr;  // IP/ether addr and UDP port of host running kernel debugger
//    EDBG_ADDR PpshHostAddr;  // IP/ether addr and UDP port of host running ether text shell
    DWORD DHCPLeaseTime;     // DHCP lease duration in seconds.
    DWORD EdbgFlags;         // Information about ethernet system
    WORD  KitlTransport; 	 // Transport for KITL communications.
    UCHAR fmtBuf[174];
} DBG_ETH_GLOBALS, *PDBG_ETH_GLOBALS;


// Store for wakeup reasons
typedef struct DECL_PACKED _WAKEUP_GLOBALS
{
    ULONG WakeUpReasons;
    ULONG NeverSleepReasons;
	ULONG StandbyState;
	ULONG SleepTime;
	UCHAR IdleProfilerEnabled;		// 0=shut idle profiler's notification to StdbyMgr OFF
	PAD(2,235);						// Pad to 256 bytes
} WAKEUP_GLOBALS, *PWAKEUP_GLOBALS;

typedef struct DECL_PACKED _dmaGlobals
{

    //
    // Event used to signal DMA IST
    //
    VOID*                   gDmacIntrEvent;

    //
    // Handle to DMA Interrupt Service Thread
    //
    VOID*                   gDmacIntrThread;

    //
	VOID*					gDmacThreadReadyEvent;
    // Table of config information for all DMA channels
    //
    DmaChannelConfigInfo    dmaChannelConfigInfo [XLLP_DMAC_CHANNEL_NUM];

    //
    // A channel array map for all DMA channels. Keeps track of channel allocation.
    // Could be moved to local config info table
    //
    XLLP_DMAC_CHANNEL_T     pArrayChannel[XLLP_DMAC_CHANNEL_NUM];

    //
    // Flag to keep track of first time initialization
    //
    BOOL                    notFirstTime;

} DMA_GLOBALS;

typedef struct DECL_PACKED _DRIVER_GLOBALS
{
    WAKEUP_GLOBALS   wup;    // Offset 0
    PCMCIA_GLOBALS   pcm;    // Offset 0x100
    PROFILE_GLOBALS  prof;   // Offset 0x200
    MISC_GLOBALS     misc;   // Offset 0x300
    PMU_GLOBALS      pmu;    // Offset 0x400
    AC97_GLOBALS     ac97;   // Offset 0x500
    PAD(0,0x200);
    // The following structs will not be zero initialized (see defs above)
    UNINIT_MISC_GLOBALS  uninit_misc;  // Offset 0x800
    DBG_ETH_GLOBALS  eth;    // Offset 0x900
} DRIVER_GLOBALS, *PDRIVER_GLOBALS;

#endif //not ASM_ONLY

//
// Constant definitions
//

//  for UNINIT_MISC_GLOBALS.offButton
#define DRVG_OFFBTN_INACTIVE      0
#define DRVG_OFFBTN_PWRBUTTON     1
#define DRVG_OFFBTN_SUSPEND       2
#define DRVG_OFFBTN_SOFT_RESET    3


//#pragma pack(pop)


#endif // _DRV_GLOB_H
